From 37fc05396ddbbfe310fa980bab39ca721ceb94b5 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 23 Sep 2013 02:45:37 +0000 Subject: [PATCH] Land QString changes that don't require (blatant) conditional compilation that are really mechanical. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4625 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/bushnell.cc | 2 +- gpsbabel/csv_util.h | 1 + gpsbabel/enigma.cc | 8 ++++---- gpsbabel/gtm.cc | 8 +++++++- gpsbabel/lowranceusr4.cc | 14 ++++++++------ gpsbabel/magellan.h | 2 +- gpsbabel/naviguide.cc | 14 ++++++-------- gpsbabel/pcx.cc | 2 +- 8 files changed, 29 insertions(+), 22 deletions(-) diff --git a/gpsbabel/bushnell.cc b/gpsbabel/bushnell.cc index a8dada3bb..af2b2fe37 100644 --- a/gpsbabel/bushnell.cc +++ b/gpsbabel/bushnell.cc @@ -242,7 +242,7 @@ bushnell_write_one(const waypoint* wpt) gbfputc(0x01, file_out); // Proximity alarm. 1 == "off", 3 == armed. ident = mkshort(mkshort_handle, wpt->shortname); - strncpy(tbuf, wpt->shortname, sizeof(tbuf)); + strncpy(tbuf, CSTRc(wpt->shortname), sizeof(tbuf)); tbuf[sizeof(tbuf)-1] = 0; gbfwrite(tbuf, sizeof(tbuf), 1, file_out); diff --git a/gpsbabel/csv_util.h b/gpsbabel/csv_util.h index ed4f2e3b5..356848135 100644 --- a/gpsbabel/csv_util.h +++ b/gpsbabel/csv_util.h @@ -40,6 +40,7 @@ csv_stringclean(const char* string, const char* chararray); CSV_STRINGCLEAN(const char* string, const char* chararray,DEBUG_PARAMS); #define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__) #endif +QString csv_stringclean(const QString& string, const char* chararray); void xcsv_data_read(void); diff --git a/gpsbabel/enigma.cc b/gpsbabel/enigma.cc index 28d75c99d..036316ed5 100644 --- a/gpsbabel/enigma.cc +++ b/gpsbabel/enigma.cc @@ -174,12 +174,12 @@ enigma_waypt_disp(const waypoint* wpt) le_write32(&ewpt.data.wp_altitude, METERS_TO_FEET(wpt->altitude) + 1000); } if (wpt->shortname != NULL) { - ewpt.shortname_len = min(6, strlen(wpt->shortname)); - strncpy(ewpt.shortname, wpt->shortname, 6); + ewpt.shortname_len = min(6, strlen(CSTRc(wpt->shortname))); + strncpy(ewpt.shortname, CSTRc(wpt->shortname), 6); } if (wpt->description != NULL) { - ewpt.longname_len = min(27, strlen(wpt->description)); - strncpy(ewpt.longname, wpt->description, 27); + ewpt.longname_len = min(27, strlen(CSTRc(wpt->description))); + strncpy(ewpt.longname, CSTRc(wpt->description), 27); } gbfwrite(&ewpt, sizeof(ewpt), 1, file_out); } diff --git a/gpsbabel/gtm.cc b/gpsbabel/gtm.cc index 2680eee96..449f8a097 100644 --- a/gpsbabel/gtm.cc +++ b/gpsbabel/gtm.cc @@ -144,7 +144,7 @@ fwrite_string(gbfile* fd, const char* str) } } static void -fwrite_string(gbfile* fd, QString& str) +fwrite_string(gbfile* fd, const QString& str) { if (str.isEmpty()) { fwrite_integer(fd, 0); @@ -170,6 +170,12 @@ fwrite_fixedstring(gbfile* fd, const char* str, int fieldlen) } } +void +fwrite_fixedstring(gbfile* fd, const QString& str, int fieldlen) +{ + fwrite_fixedstring(fd, CSTR(str), fieldlen); +} + /* Auxiliar functions */ #define MAX_INDATUM_INDEX 263 diff --git a/gpsbabel/lowranceusr4.cc b/gpsbabel/lowranceusr4.cc index 8d27c6406..5b7a2f245 100644 --- a/gpsbabel/lowranceusr4.cc +++ b/gpsbabel/lowranceusr4.cc @@ -108,13 +108,11 @@ lowranceusr4_readstr(char* buf, const int maxlen, gbfile* file, int bytes_per_ch } static void -lowranceusr4_writestr(char* buf, gbfile* file, unsigned int bytes_per_char) +lowranceusr4_writestr(const QString& buf, gbfile* file, unsigned int bytes_per_char) { unsigned int len = 0; - if (buf) { - len = strlen(buf); - } + len = buf.length(); if (0xffffffff / bytes_per_char < len) { /* be pedantic and check for the unlikely event that we are asked @@ -125,10 +123,10 @@ lowranceusr4_writestr(char* buf, gbfile* file, unsigned int bytes_per_char) gbfputint32(len*bytes_per_char, file_out); if (bytes_per_char == 1) { - (void) gbfwrite(buf, 1, len, file); + (void) gbfwrite(CSTR(buf), 1, len, file); } else { for (unsigned int i = 0; i < len; ++i) { - gbfputc(buf[i], file_out); + gbfputc(buf[i].cell(), file_out); for (unsigned int j = 1; j < bytes_per_char; ++j) { gbfputc('\0', file_out); } @@ -287,7 +285,11 @@ static char same_points(const waypoint* A, const waypoint* B) { return ( /* !!! We are case-sensitive !!! */ +#if NEW_STRINGS + (A->shortname == B->shortname) && +#else (strcmp(A->shortname, B->shortname) == 0) && +#endif (A->latitude == B->latitude) && (A->longitude == B->longitude)); } diff --git a/gpsbabel/magellan.h b/gpsbabel/magellan.h index e910f029d..fbc47aa6a 100644 --- a/gpsbabel/magellan.h +++ b/gpsbabel/magellan.h @@ -48,7 +48,7 @@ QString mag_find_descr_from_token(const char* token); QString mag_find_token_from_descr(const QString& icon); unsigned int mag_checksum(const char* const buf); -char* m330_cleanse(char* istring); +char* m330_cleanse(const char* istring); waypoint* mag_trkparse(char* trkmsg); void mag_rteparse(char* rtemsg); diff --git a/gpsbabel/naviguide.cc b/gpsbabel/naviguide.cc index 28dc91f6e..540ff9399 100644 --- a/gpsbabel/naviguide.cc +++ b/gpsbabel/naviguide.cc @@ -130,16 +130,15 @@ ng_convert_datum(waypoint* wpt) /*=================== File read/write utilities ==========================================*/ static void -ng_fwrite_wp_data(char* s, char* d, ng_wp_data_t* wp_data, gbfile* f) +ng_fwrite_wp_data(const QString& s, const QString& d, ng_wp_data_t* wp_data, gbfile* f) { int i; char z[50]; memset(z, 0, 50); - - i = (s == NULL) ? 0 : strlen(s); + i = s.length(); gbfwrite(&i, 1, 1, f); - gbfwrite(s, 1, i, f); + gbfwrite(CSTR(s), 1, i, f); gbfwrite(&wp_data->pad1[0], 8, 1, f); gbfputint32(wp_data->East, f); @@ -147,9 +146,9 @@ ng_fwrite_wp_data(char* s, char* d, ng_wp_data_t* wp_data, gbfile* f) gbfwrite(&wp_data->pad2[0], 2, 1, f); gbfputint32(wp_data->Alt, f); - i = (d == NULL) ? 0 : strlen(d); + i = d.length(); gbfwrite(&i, 1, 1, f); - gbfwrite(d, 1, i, f); + gbfwrite(CSTR(d), 1, i, f); gbfwrite(z, 44, 1, f); } @@ -238,8 +237,6 @@ ng_fill_waypoint_default(void) static void ng_waypt_rd(const waypoint* wpt) { - char* s = NULL; - char z[50]; double lat, lon; static int current_wp_ix=0; @@ -255,6 +252,7 @@ ng_waypt_rd(const waypoint* wpt) WPNC.wp_data.North = (int32_t)lat; WPNC.wp_data.East = (int32_t)lon; + String s; if (reorder_wp) { sprintf(temp_short_name, "A%03d", current_wp_ix); s = temp_short_name; diff --git a/gpsbabel/pcx.cc b/gpsbabel/pcx.cc index 404f91ac9..4d39f710a 100644 --- a/gpsbabel/pcx.cc +++ b/gpsbabel/pcx.cc @@ -345,7 +345,7 @@ gpsutil_disp(const waypoint* wpt) gbfprintf(file_out, "W %-6.6s %c%08.5f %c%011.5f %s %5.f %-40.40s %5e %d\n", global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, wpt) : - wpt->shortname, + CSTRc(wpt->shortname), lat < 0.0 ? 'S' : 'N', fabs(lat), lon < 0.0 ? 'W' : 'E', -- 2.30.2